#include "thread1.h"
#include <QDebug>

thread1::thread1(QObject *parent) :
    QThread(parent)
{
}

void thread1::wakeFunc()
{
    if(!isRunning()){
        start();
    }else{
        cond.wakeOne();
    }
}

void thread1::run()
{
    static int x=0;
    qDebug()<<"进入thread1的run函数";

    while(true){
        qDebug()<<"-------> 1 <---------";

        mutex.lock();
        if(++x>3) th2.start();
        qDebug() << "进入thread1的while循环,x值为"<<x;
        cond.wait(&mutex);   //当处于wait状态时mutex会被暂时释放，并阻塞在这个地方；当线程被cond.wakeOne()等唤醒时，mutex又会被重新锁定，并继续运行
        mutex.unlock();


        qDebug()<<"-------> 2 <---------";
    }
}
